package master

import (
	"github.com/hwcer/cosgo/binder"
	"github.com/hwcer/cosgo/values"
	"github.com/hwcer/cosmo"
	"github.com/hwcer/yyds/context"
	"github.com/hwcer/yyds/options"
	"github.com/hwcer/yyds/players"
	"github.com/hwcer/yyds/players/player"
	"server/game/model"
)

var db = model.DB()

func Register(i interface{}, name ...string) {
	context.RegisterPrivate(i, name...)
}

type Paging struct {
	cosmo.Paging
	Key   string
	Value string
}

// Send 推送消息
func Send(uid string, v any, rp any) error {
	req := player.GetReqMeta(rp)
	if req == nil {
		return values.Errorf(0, "send:rp type error:%v", rp)
	}
	req.Set(binder.HeaderContentType, options.Options.Binder)
	err := players.Get(uid, func(player *player.Player) error {
		player.Send(v, req)
		return nil
	})
	return err
}
